﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Security;

namespace WebshopPizzaRio
{
    public partial class WinkelwagenOverzicht : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            ShoppingCart cart = (ShoppingCart)Session["shoppingcart"];
            winkelwagenoverzicht_LV.DataSource = cart.getShoppingCart;
            winkelwagenoverzicht_LV.DataBind();
        }

        protected void bt_nextstap_Click(object sender, EventArgs e)
        {
            ShoppingCart cart = (ShoppingCart)Session["shoppingcart"];
            MembershipUser currentuserid = Membership.GetUser();

            if (cart.getShoppingCart.Count > 0)
            {
                try
                {
                    if ((Guid)currentuserid.ProviderUserKey == null)
                    {
                        throw new NullReferenceException();
                    }
                    else
                    {
                        Response.Redirect("Bestelling-user.aspx");
                    }
                }
                catch (NullReferenceException)
                {
                    Response.Redirect("Bestelling-controle.aspx");
                }
            }
            else
            {
                lbl_showerrorwinkelwagenleeg.Visible = true;
            }
        }

        protected void winkelwagenoverzicht_LV_SelectedIndexChanging(object sender, ListViewSelectEventArgs e)
        {
            ShoppingCart cart = (ShoppingCart)Session["shoppingcart"];
            winkelwagenoverzicht_LV.SelectedIndex = e.NewSelectedIndex;

            Items deletepizza = cart.getNewItem();
            deletepizza.PizzaID = int.Parse(winkelwagenoverzicht_LV.SelectedDataKey.Values["pizzaid"].ToString());
            cart.DeleteItem(deletepizza);

            winkelwagenoverzicht_LV.DataBind();
            ListView listviewmp;
            listviewmp = (ListView)(Master).FindControl("ListView1");
            listviewmp.DataBind();

            Label label1mp;
            label1mp = (Label)(Master).FindControl("label1");
            label1mp.Text = "Totaal bedrag: € " + cart.getTotaalBedrag();
        }
    }
}